#include "lvgl.h"

#ifndef WEEK_FONT
#define WEEK_FONT 1
#endif

#if WEEK_FONT

/*-----------------
 *    BITMAPS
 *----------------*/

/*Store the image of the glyphs*/
static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {

    /* U+4e00 "一" */
    0xff, 0xff, 0xff, 0xff, 0x18, 

    /* U+4e09 "三" */
    0x7f, 0xff, 0xff, 0xff, 0x40, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x55, 0x55, 0x55, 0x40, 0x7f, 0xff, 
    0xff, 0xf4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0xf, 0xff, 0xff, 0xff, 0x7e, 

    /* U+4e8c "二" */
    0xa, 0xaa, 0xaa, 0xaa, 0x80, 0x3f, 0xff, 0xff, 
    0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0xaa, 0xaa, 
    0xaa, 0xaa, 0x9f, 0xff, 0xff, 0xff, 0xff, 0x18, 

    /* U+4e94 "五" */
    0x2f, 0xff, 0xff, 0xff, 0xe0, 0xbf, 0xff, 0xff, 
    0xff, 0x80, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x0, 
    0xb0, 0x0, 0x0, 0x0, 0x3, 0x80, 0x0, 0x0, 
    0x0, 0xd, 0x0, 0x0, 0x0, 0x55, 0xb5, 0x55, 
    0x50, 0x3, 0xff, 0xff, 0xff, 0xc0, 0x0, 0xf, 
    0x0, 0xb, 0x0, 0x0, 0x34, 0x0, 0x1c, 0x0, 
    0x1, 0xd0, 0x0, 0x70, 0x0, 0x7, 0x0, 0x1, 
    0xc0, 0x0, 0x2c, 0x0, 0x7, 0x0, 0x0, 0xe0, 
    0x0, 0x1c, 0x0, 0x3, 0x40, 0x0, 0x70, 0x1a, 
    0xbf, 0xaa, 0xab, 0xe9, 0xbf, 0xff, 0xff, 0xff, 
    0x7c, 

    /* U+516d "六" */
    0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x3, 0xc0, 
    0x0, 0x0, 0x0, 0x7, 0x40, 0x0, 0x0, 0x0, 
    0xf, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x1, 
    0xaa, 0xaa, 0xaa, 0xaa, 0x97, 0xff, 0xff, 0xff, 
    0xff, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x38, 0x3, 0x40, 0x0, 
    0x1, 0xd0, 0xf, 0x40, 0x0, 0xe, 0x0, 0xf, 
    0x0, 0x0, 0xf0, 0x0, 0xf, 0x0, 0xb, 0x40, 
    0x0, 0x1e, 0x0, 0x78, 0x0, 0x0, 0x3d, 0x7, 
    0xc0, 0x0, 0x0, 0x3c, 0x3c, 0x0, 0x0, 0x0, 
    0x7a, 0xc0, 0x0, 0x0, 0x0, 0x20, 

    /* U+56db "四" */
    0xff, 0xff, 0xff, 0xff, 0xf8, 0xf, 0x7, 0x40, 
    0xbd, 0x3, 0xc1, 0xd0, 0x1f, 0x40, 0xe0, 0x74, 
    0x7, 0xd0, 0x38, 0x1d, 0x1, 0xf4, 0xd, 0x7, 
    0x40, 0x7d, 0x3, 0x41, 0xd0, 0x1f, 0x41, 0xd0, 
    0x74, 0x7, 0xd0, 0xb0, 0x1d, 0x1, 0xf4, 0x3c, 
    0x7, 0x40, 0x7d, 0x3d, 0x0, 0xfa, 0x1f, 0xae, 
    0x0, 0x2f, 0xd7, 0xee, 0x0, 0x0, 0x1, 0xf4, 
    0x0, 0x0, 0x0, 0x7d, 0x0, 0x0, 0x0, 0x1f, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
    0xf4, 0x0, 0x0, 0x0, 0x1c, 

    /* U+65e5 "日" */
    0xff, 0xff, 0xff, 0xf9, 0x55, 0x55, 0xbd, 0x0, 
    0x0, 0x1f, 0x40, 0x0, 0x7, 0xd0, 0x0, 0x1, 
    0xf4, 0x0, 0x0, 0x7d, 0x0, 0x0, 0x1f, 0xff, 
    0xff, 0xff, 0xff, 0xff, 0xff, 0xf4, 0x0, 0x0, 
    0x7d, 0x0, 0x0, 0x1f, 0x40, 0x0, 0x7, 0xd0, 
    0x0, 0x1, 0xf4, 0x0, 0x0, 0x7d, 0x0, 0x0, 
    0x1f, 0xff, 0xff, 0xff, 0xe5, 0x55, 0x56, 0xf4, 
    0x0, 0x0, 0x1c, 

    /* U+661f "星" */
    0xb, 0xff, 0xff, 0xff, 0x80, 0x2c, 0x0, 0x0, 
    0xe, 0x0, 0xb5, 0x55, 0x55, 0x78, 0x2, 0xff, 
    0xff, 0xff, 0xe0, 0xb, 0x0, 0x0, 0x3, 0x80, 
    0x2d, 0x55, 0x55, 0x5e, 0x0, 0xbf, 0xff, 0xff, 
    0xf8, 0x0, 0x80, 0xd, 0x0, 0x0, 0x7, 0x40, 
    0x34, 0x0, 0x0, 0x3f, 0xff, 0xff, 0xff, 0xc3, 
    0xea, 0xab, 0xea, 0xa9, 0x2e, 0x0, 0xd, 0x0, 
    0x0, 0x26, 0xaa, 0xbe, 0xaa, 0x80, 0x1f, 0xff, 
    0xff, 0xff, 0x0, 0x0, 0x3, 0x40, 0x0, 0x0, 
    0x0, 0x1e, 0x0, 0x0, 0x7f, 0xff, 0xff, 0xff, 
    0x7a, 

    /* U+671f "期" */
    0xe, 0x3, 0x81, 0x55, 0x50, 0xe0, 0x38, 0x3f, 
    0xff, 0x6f, 0xab, 0xe7, 0xc0, 0xbb, 0xff, 0xff, 
    0x7c, 0x7, 0xe, 0x3, 0x83, 0xc0, 0x70, 0xe0, 
    0x38, 0x3d, 0x5b, 0xf, 0xff, 0x83, 0xff, 0xf0, 
    0xf5, 0x78, 0x3c, 0xb, 0xe, 0x3, 0x83, 0xc0, 
    0x70, 0xfa, 0xb8, 0x3c, 0x7, 0xf, 0xff, 0x83, 
    0xd5, 0xb0, 0xe0, 0x38, 0x3f, 0xff, 0xe, 0x3, 
    0x83, 0x80, 0x7f, 0xff, 0xff, 0x74, 0x7, 0x55, 
    0x55, 0x57, 0x40, 0x70, 0x34, 0xb0, 0xb0, 0x7, 
    0xf, 0x7, 0x4f, 0x0, 0x77, 0xd0, 0x2a, 0xd0, 
    0xff, 0x20, 0x0, 0x8, 0xb, 0x34, 
};

/*---------------------
 *  GLYPH DESCRIPTION
 *--------------------*/

static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
/* id = 0 reserved */  {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0},
/* U+4e00 "一" */  {.bitmap_index = 0, .adv_w = 328, .box_w = 17, .box_h = 1, .ofs_x = 2, .ofs_y = 8},
/* U+4e09 "三" */  {.bitmap_index = 5, .adv_w = 328, .box_w = 17, .box_h = 15, .ofs_x = 2, .ofs_y = 0},
/* U+4e8c "二" */  {.bitmap_index = 69, .adv_w = 328, .box_w = 19, .box_h = 15, .ofs_x = 1, .ofs_y = 0},
/* U+4e94 "五" */  {.bitmap_index = 141, .adv_w = 328, .box_w = 19, .box_h = 17, .ofs_x = 1, .ofs_y = -1},
/* U+516d "六" */  {.bitmap_index = 222, .adv_w = 328, .box_w = 19, .box_h = 18, .ofs_x = 1, .ofs_y = -1},
/* U+56db "四" */  {.bitmap_index = 308, .adv_w = 328, .box_w = 17, .box_h = 18, .ofs_x = 2, .ofs_y = -2},
/* U+65e5 "日" */  {.bitmap_index = 385, .adv_w = 328, .box_w = 13, .box_h = 18, .ofs_x = 4, .ofs_y = -2},
/* U+661f "星" */  {.bitmap_index = 444, .adv_w = 328, .box_w = 19, .box_h = 17, .ofs_x = 1, .ofs_y = -1},
/* U+671f "期" */  {.bitmap_index = 525, .adv_w = 328, .box_w = 18, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
};

/*---------------------
 *  CHARACTER MAPPING
 *--------------------*/

static const uint16_t unicode_list_1[] = {

    0x4e00, 0x4e09, 0x4e8c, 0x4e94, 0x516d, 0x56db, 0x65e5, 0x661f, 
    0x671f, 
};

/*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] =
{
    {
        .range_start = 0, .range_length = 26399, .glyph_id_start = 1,
        .unicode_list = unicode_list_1, .glyph_id_ofs_list = NULL, .list_length = 9, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
    }
};

/*--------------------
 *  ALL CUSTOM DATA
 *--------------------*/
/*Store all the custom data of the font*/
static lv_font_fmt_txt_dsc_t font_dsc = {
    .glyph_bitmap = gylph_bitmap,
    .glyph_dsc = glyph_dsc,
    .cmaps = cmaps,
    .kern_dsc = NULL,
    .kern_scale = 0,
    .cmap_num = 1,
    .bpp = 2,
    .kern_classes = 0,
    .bitmap_format = 0
};

/*-----------------
 *  PUBLIC FONT
 *----------------*/

/*Initialize a public general font descriptor*/
lv_font_t week_font = {
    .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt,    /*Function pointer to get glyph's data*/
    .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt,    /*Function pointer to get glyph's bitmap*/
    .line_height = 28,          /*The maximum line height required by the font*/
    .base_line = 6,             /*Baseline measured from the bottom of the line*/
#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
    .subpx = LV_FONT_SUBPX_NONE,
#endif
    .dsc = &font_dsc           /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
};
#endif /*#if WEEK_FONT*/
